home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
dialogs
/
search.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
3KB
|
104 lines
const REGULAR_TYPE = "http://home.netscape.com/NC-rdf#Bookmark";
var gNode = window.arguments[0].node;
var engines = {
'google' : {
max : 32,
parseUrl : function (str) {
return str;
},
mkurl : function (request, list) {
var l = Math.min(list.length, engines.google.max);
var str = ' site:' + list[0];
for (var i = 1; i < l; i++) {
str += ' OR site:' + list[i];
}
var url = 'http://www.google.com/search?q=' + request + str;
return encodeURI(url);
}
},
'yahoo' : {
max:32,
parseUrl : function(str) {
return getHostFromUrl(str);
},
mkurl : function (request, list) {
var l = Math.min(list.length, engines.yahoo.max);
var str = list[0];
for (var i = 1; i < l; i++) {
str += ' OR ' + list[i];
}
var url = 'http://fr.search.yahoo.com/search?va=' + request + '&vs=' + str;
return encodeURI(url);
}
}
}
function search() {
var value = document.getElementById("yoono-search-input").engine;
var engine = engines[value];
var request = document.getElementById("yoono-search-input").value;
var urllist = getUrlList(engine);
var target = engine.mkurl(request, urllist);
var where = "tab";
// need try here :
// see https://bugzilla.mozilla.org/show_bug.cgi?id=330036
try {
window.opener.openUILinkIn(target, where);
} catch (e) {}
}
function getUrlList(engine) {
var obj = {
list : [],
count : 0,
max : engine.max,
parseUrl : engine.parseUrl,
onNode : function (node) {
if ((node.isBookmark()) && (this.count < this.max)) {
var addr = this.parseUrl(node.getUrl());
if (addr) {
this.list.push(addr);
this.count++;
}
}
}
}
gNode.traverseNode(obj, 'force');
return obj.list;
}
function countBkms(node) {
var obj = {
count : 0,
onNode : function (node) {
if ((node.getType() == REGULAR_TYPE)) {
this.count++;
}
}
}
node.traverseNode(obj, 'force');
return obj.count;
}
function switchengine(event) {
var menuitem = event.target;
var button = menuitem.parentNode.parentNode;
button.setAttribute('src', menuitem.getAttribute('image'));
button.setAttribute('value', menuitem.getAttribute('value'));
}
function init() {
var strbundle=document.getElementById("yoono-strings");
var desc = strbundle.getString("search.desc");
var count = countBkms(gNode);
desc = desc.replace('%1', count);
var text = document.createTextNode(desc);
var descEl = document.getElementById("yoono-search-description");
descEl.appendChild(text);
centerWindow();
}